import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { HttpExceptionFilter } from './common/interceptor/http-exception.filter';
import { ResponseInterceptor } from './common/interceptor/response.interceptor';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useGlobalFilters(new HttpExceptionFilter());
  app.useGlobalInterceptors(new ResponseInterceptor());

  // 启用CORS
  app.enableCors({
    origin: true, // 允许的前端地址
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
    credentials: true, // 允许携带凭证（如cookies）
  });

  console.log('Starting server...');
  await app.listen(3000, '0.0.0.0');
}
// 修复：使用.catch处理Promise可能的拒绝情况
bootstrap().catch((error) => {
  console.error('An error occurred during server startup:', error);
});
